package com.company.huisuo.biz.activity

import android.app.Activity
import android.content.Intent
import androidx.lifecycle.lifecycleScope
import com.company.huisuo.base.BaseActivity
import com.company.huisuo.biz.bean.ArtistBean
import com.company.huisuo.biz.dialog.ArtistInfoDialog
import com.company.huisuo.biz.dialog.ArtistRewardDataDialog
import com.company.huisuo.databinding.ActivityArtistInfoBinding
import com.company.huisuo.ext.loadCircleImg
import com.company.huisuo.ext.loadImg
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BasePopupView
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 艺人选秀-确定艺人
 */
class ArtistInfoActivity : BaseActivity<ActivityArtistInfoBinding>() {

    private var mDialog: BasePopupView? = null

    companion object {
        fun start(activity: Activity, bean: ArtistBean?) {
            Intent(activity, ArtistInfoActivity::class.java).apply {
                putExtra("artist", bean)
                activity.startActivity(this)
            }
        }
    }

    override fun initView() {
        val bean = intent.getParcelableExtra<ArtistBean>("artist")

        mBinding.ivBack.setOnClickListener {
            finish()
        }
        mDialog = XPopup.Builder(this).asCustom(ArtistInfoDialog(this@ArtistInfoActivity, bean) {

        })

        mBinding.clLayout.setOnClickListener {
            if (mDialog?.isShow == false) {
                mDialog?.show()
            }
        }

        lifecycleScope.launch {
            delay(500)
            mDialog?.show()
        }

        bean?.also {
            mBinding.ivAvatar.loadCircleImg(it.avatar)
            mBinding.tvName.text = it.name
            mBinding.ivArtist.loadImg(it.background)
        }
    }

    override fun initData() {

    }
}